package com.exam.util;

import com.exam.pojo.ApiResult;

public class ApiResultHandler {
    public static ApiResult success(Object object) {
        ApiResult apiResult = new ApiResult();
        apiResult.setData(object);
        apiResult.setCode(200);
        apiResult.setMessage("请求成功");
        return apiResult;
    }
    //无数据data返回值给前端
    public static ApiResult success1(){
           ApiResult apiResult = new ApiResult();
           apiResult.setCode(200).setMessage("请求成功").setData(null);
           return apiResult;

}
    //有返回值
    public static ApiResult success2(Object data){
        ApiResult apiResult = new ApiResult();
        apiResult.setCode(200).setMessage("请求成功").setData(data);
        return apiResult;
    }
    //请求失败
    public static ApiResult failed(){
        ApiResult apiResult =new ApiResult();
        apiResult.setCode(400).setMessage("请求失败").setData(null);
        return apiResult;

    }
    public static ApiResult success() {
        return success(null);
    }
    public static <T> ApiResult buildApiResult(Integer code,String message,T data){
        ApiResult apiResult = new ApiResult();
        apiResult.setCode(code).setMessage(message).setData(data);
        return apiResult;
    }
}
